import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Router, NavigationEnd, NavigationStart } from '@angular/router';
import { Pagination } from '../../../public/serve/pcrudInfo';
import { Service } from '../../../server/server';
import { CudTableService } from '../../../public/serve/cud-table/cud-table.service';
import { RemoveTableService } from '../../../public/serve/remove-table/remove-table.service';
declare var $: any;

@Component({
  selector: 'app-message',
  templateUrl: './message.component.html'
})
export class MessageComponent implements OnInit {

  constructor(
    private server: Service,
    private tableListService: CudTableService,
    public removeTableService: RemoveTableService,
    public router: Router
  ) { }


  ngOnInit() {

    //登录第一次弹出
    // this.websocketService.openModel.subscribe((value: any) => {
    //   this.counts = value;
    // })

    // //点击消息
    // this.cancelhornClickEimt = this.websocketService.hornClick.subscribe((value: any) => {
    //   //this.getTabList(1,20,this.userId,0,'');
    //   //this.websocketService.hornClick.emit();
    //   if (value == "open-model") {
    //     setTimeout(() => {
    //       //console.log(this.counts)
    //       $("#message").modal("show");
    //     }, 300);
    //   }
    // });

    //订单计数
    this.cancelMessageOrderEimt = this.server.messageOrder.subscribe((value: any) => {
      this.countsOrder = value;
    })
    //入库计数
    this.cancelMessageStorageEimt = this.server.messageStorage.subscribe((value: any) => {
      this.countsStorage = value;
    })
    //合同计数
    this.cancelMessageContractEimt = this.server.messageContract.subscribe((value: any) => {
      this.countsContract = value;
    })
  }

  //取消订阅
  public cancelhornClickEimt: any;
  public cancelMessageOrderEimt: any;
  public cancelMessageStorageEimt: any;
  public cancelMessageContractEimt:any;
  ngOnDestroy() {
    if (this.cancelhornClickEimt || this.cancelMessageOrderEimt || this.cancelMessageStorageEimt) {
      this.cancelhornClickEimt.unsubscribe();
      this.cancelMessageOrderEimt.unsubscribe();
      this.cancelMessageStorageEimt.unsubscribe();
    }
  }


  public countsOrder: any = 0;
  public countsStorage: any = 0;
  public countsContract:any = 0;
  //切换tab 0订单 1入库 2合同
  public tabSwitch: number = 0;
  public tab(val) {
    this.tabSwitch = val;
    this.removeTableService.getRemoveTableId = [];
    //this.websocketService.hornClick.emit();
  }
  public counts: any = 0;

  ngDoCheck() {
    this.counts = Number(this.countsOrder) + Number(this.countsStorage) + Number(this.countsContract);
  }

}
